package com.mcp.server.service;

import cn.hutool.core.util.StrUtil;
import com.mcp.server.utils.EmailUtils;
import jakarta.annotation.Resource;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class EmailService {

    @Resource
    EmailUtils emailUtils;



    @Tool(name = "sendEmail", description = "发送一封普通的电子邮件")
    public String sendEmail(
            @ToolParam(description = "收件人邮箱地址") String to,
            @ToolParam(description = "邮箱主题") String subject,
            @ToolParam(description = "邮箱内容") String content){
        emailUtils.sendEmail(subject,content,to);
        return "发送成功";
    }

    @Tool(name = "sendEmailFile", description = "发送带有附件的电子邮件")
    public String sendEmailFile(
            @ToolParam(description = "邮箱主题")String subject,
            @ToolParam(description = "邮箱内容") String content,
            @ToolParam(description = "收件人邮箱地址") String to ,
            @ToolParam(description = "附件的名称", required = false) String attachmentFilename,
            @ToolParam(description = "附件的文件路径") String path){
        File file = new File(path);
        if (!file.isFile()){
            return "请提供正确的文件路径";
        }
        if (StrUtil.isEmptyIfStr(attachmentFilename)){
            attachmentFilename = file.getName();
        }
        emailUtils.sendEmailMultipart(subject, content, to , attachmentFilename, file);
        return "发送成功";
    }


}
